package server.model.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javafx.beans.binding.When;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@DynamicInsert
@DynamicUpdate
@ApiModel("用户表")
public class Users {
    @Id
    @GeneratedValue(generator = "UuidProduce")
    @GenericGenerator(name = "UuidProduce", strategy = "server.tool.idProduce.UuidProduce")
    private String id;

    @Column(unique = true)
    private String name;

    @Column
    private String password;

    @Column(unique = true)
    private String userName;

    @Column(unique = true)
    private String mobile;

    @Column
    private Boolean status;

    @Column
    private String type;

    @ManyToOne
    @JoinColumn(name = "roleId")
    private FrmRole role;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @LastModifiedDate
    @Column
    private Date modifiedTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @CreatedDate
    @Column
    private Date createTime;

    private String parentId;

    private String parentName;

    private String tree;

    private Integer treeNum;

    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum Grade {
        GENERAL("普通用户",1),
        VIP("会员",2),
        COLONEL("团长",3),
        MANAGER("经理",4),
        MAJOR("总监",5),
        TRUSTEE("董事",6),
        CEO("CEO",7);

        Grade(String display,Integer num) {
            this.display = display;
            this.num = num;
        }

        private String display;

        private Integer num;

        public Integer getNum() {
            return num;
        }

        public void setNum(Integer num) {
            this.num = num;
        }

        public String getDisplay() {
            return display;
        }

        public void setDisplay(String display) {
            this.display = display;
        }

        public static  Grade getNumBy(Integer num) {
            switch (num){
                case 1:return Grade.GENERAL;
                case 2:return Grade.VIP;
                case 3:return Grade.COLONEL;
                case 4:return Grade.MANAGER;
                case 5:return Grade.MAJOR;
                case 6:return Grade.TRUSTEE;
                case 7:return Grade.CEO;
                default:return Grade.GENERAL;
            }
        }
    }

    @Enumerated(EnumType.STRING)
    @Column
    @ApiModelProperty("等级")
    private Grade grade;

    private Integer inviteNum;

    private Integer performance;

    private Integer selfPerformance;

    private Boolean active;
}
